package com.googlecode.animator.core
{
	import com.googlecode.animator.controller.AddCameraCommand;
	import com.googlecode.animator.controller.AddGlobalMarkerCommand;
	import com.googlecode.animator.controller.AddObject3DCommand;
	import com.googlecode.animator.controller.AddSceneCommand;
	import com.googlecode.animator.controller.PlayCommand;
	import com.googlecode.animator.controller.StartupCommand;
	import com.googlecode.animator.data.Notifications;
	
	import mx.core.Application;
	
	import org.puremvc.as3.multicore.patterns.facade.Facade;
	
	
	/**
	 * PureMVC Facade implementation for WebPlayer
	 * 
	 * Implements the Singleton interface.
	 *  
	 * @author Martin
	 */
	public class Animator3DPlayerFacade extends Facade
	{
		public function Animator3DPlayerFacade(key:String)
		{
			super(key);
		}
		
		/**
		 * Application startup function.
		 * @param appRef Reference to the main application instance.
		 */
		/* public static function start(appRef:Application):void
		{//trace("j"+appRef, getInstance());
			getInstance().sendNotification(Notifications.APPLICATION3DPLAYER_START, appRef);
		}
		
		static public function getInstance():Animator3DPlayerFacade
		{
			
			if(instance == null)
			{
				instance = new Animator3DPlayerFacade();
			}
			trace("WWW"+instance is Animator3DPlayerFacade, instance as Animator3DPlayerFacade);
			return instance as Animator3DPlayerFacade;
		} */
		
		/**
		 * Return multiton instance. 
		 * @return 
		 */
		public static function getInstance(key:String):Animator3DPlayerFacade
		{
			if(!hasCore(key))
			{
				instanceMap[key] = new Animator3DPlayerFacade(key);
			}
			
			return instanceMap[key] as Animator3DPlayerFacade;
		}


		/**
		 * Application startup function.
		 * @param appRef Reference to the main application instance.
		 */
		public static function start(appKey:String, appRef:Application):void
		{
			//trace("START", appKey, appRef);
			getInstance(appKey).sendNotification(Notifications.APPLICATION3DPLAYER_START, appRef);
		}
		
		override protected function initializeController():void
		{
			super.initializeController();
			
			// startup command
			// Note: No Mediators registered at this stage
			registerCommand(Notifications.APPLICATION3DPLAYER_START, StartupCommand);
			
			registerCommand(Notifications.ADD_SCENE, AddSceneCommand);	
			
			registerCommand(Notifications.ADD_GLOBAL_MARKER, AddGlobalMarkerCommand);
			
			registerCommand(Notifications.ADD_CAMERA, AddCameraCommand);
			
			registerCommand(Notifications.ADD_OBJECT3D, AddObject3DCommand);
			
			registerCommand(Notifications.PLAY, PlayCommand);	
			
		}

	}
}